class CarBrandsController < ApplicationController
  before_action :set_menu

  def index
    @submenu = :car_brand
    @title = '车型管理'
    @car_brands = CarBrand.all
  end

  def new
    @car_brand = CarBrand.new
  end

  def create
    @car_brand = CarBrand.new post_params
    if @car_brand.save
      redirect_to car_brands_path
    else
      render :action => 'new'
    end
  end

  def edit
    @car_brand = CarBrand.find params[:id]
  end

  def update
    @car_brand = CarBrand.find params[:id]
    if @car_brand.update_attributes post_params
      redirect_to car_brands_path
    else
      render :action => 'edit'
    end
  end

  def destroy
    @car_brand = CarBrand.find params[:id]
    @car_brand.destroy
    redirect_to car_brands_path
  end

  def show
    @title = "车型管理/明细"
    @buttons.push :action => car_brands_path, :label => "返回"
    @car_brand = CarBrand.find params[:id]
  end

  def car_mo_check
    @customer = Customer.new
    @car_brands = CarBrand.where(is_show: true)
  end


  def post_params
    params.require(:car_brand).permit(*%w(name is_show))
  end

  private
  def set_menu
    @mainmenu = :base_data
  end
end
